/**
 * 数组列表测试
 *
 * @author jacob
 * @date 2025/6/6 14:52
 */

#include "testArrayList.h"

/*
 * 测试数组列表
 */
void testArrayList(void) {
    // 定义数组列表
    ArrayList* a = NULL;

    // 测试:未初始化数组列表销毁，预期destroyRes为false，打印"测试:数组列表销毁失败"
    bool destroyRes = destroyArrayList(a);
    if (destroyRes) {
        printf("测试:数组列表销毁成功\n");
    }
    else {
        printf("测试:数组列表销毁失败\n");
    }
    printf("\n");

    // 测试:数组列表初始化，预期isEmptyRes为true，数组长度为0，列表容量为10，打印"测试:数组列表长度:0"、"测试:数组列表容量:10"、"测试:数组列表为空"
    a = initArrayList();
    printf("测试:数组列表长度:%d\n", sizeArrayList(a));
    printf("测试:数组列表容量:%d\n", capacityArrayList(a));
    bool isEmptyRes = isEmptyArrayList(a);
    if (isEmptyRes) {
        printf("测试:数组列表为空\n");
    }
    else {
        printf("测试:数组列表不为空\n");
    }
    printf("\n");

    // 测试:数组列表插入节点，预期insertRes为true，isEmptyRes为false，数组长度为0，列表容量为10，打印"测试:数组列表插入节点成功"、"测试:数组列表长度:1"、"测试:数组列表容量:10"、"测试:数组列表不为空"
    Node* value = (Node*)malloc(sizeof(Node));
    value->valueA = 3;
    value->valueB = 4;
    bool insertRes = insertArrayList(a, 0, value);
    if (insertRes) {
        printf("测试:数组列表插入节点成功\n");
    }
    else {
        printf("测试:数组列表插入节点失败\n");
    }
    printf("测试:数组列表长度:%d\n", sizeArrayList(a));
    printf("测试:数组列表容量:%d\n", capacityArrayList(a));
    isEmptyRes = isEmptyArrayList(a);
    if (isEmptyRes) {
        printf("测试:数组列表为空\n");
    }
    else {
        printf("测试:数组列表不为空\n");
    }
    Node* value1 = (Node*)malloc(sizeof(Node));
    value1->valueA = 5;
    value1->valueB = 6;
    insertRes = insertArrayList(a, 0, value1);
    Node* value2 = (Node*)malloc(sizeof(Node));
    value2->valueA = 7;
    value2->valueB = 8;
    insertRes = insertArrayList(a, 0, value2);
    insertRes = insertArrayList(a, 0, value2);
    insertRes = insertArrayList(a, 0, value2);
    insertRes = insertArrayList(a, 0, value2);
    insertRes = insertArrayList(a, 0, value2);
    insertRes = insertArrayList(a, 0, value2);
    insertRes = insertArrayList(a, 0, value2);
    insertRes = insertArrayList(a, 0, value2);
    printf("\n");

    // 测试:数组列表自动扩容，预期数组长度为10，列表容量为10，数组长度为11，列表容量为15
    printf("测试:数组列表长度:%d\n", sizeArrayList(a));
    printf("测试:数组列表容量:%d\n", capacityArrayList(a));
    insertRes = insertArrayList(a, 0, value2);
    printf("测试:数组列表长度:%d\n", sizeArrayList(a));
    printf("测试:数组列表容量:%d\n", capacityArrayList(a));
    printf("\n");

    // 测试:数组列表打印
    for (int i = 0;i < sizeArrayList(a);i++) {
        Node* data = getArrayList(a, i);
        printf("第%d个节点:valueA=%d,valueB=%d\n", i, data->valueA, data->valueB);
    }
    printf("\n");

    // 测试:数组列表设置节点，预期setRes为true，打印"测试:数组列表设置节点成功"、"第1个节点:valueA=9,valueB=10"
    Node* value3 = (Node*)malloc(sizeof(Node));
    value3->valueA = 9;
    value3->valueB = 10;
    bool setRes = setArrayList(a, 1, value3);
    if (setRes) {
        printf("测试:数组列表设置节点成功\n");
    }
    else {
        printf("测试:数组列表设置节点失败\n");
    }
    Node* data = getArrayList(a, 1);
    printf("第%d个节点:valueA=%d,valueB=%d\n", 1, data->valueA, data->valueB);
    printf("\n");

    // 测试:数组列表删除节点，预期removeRes为true，打印"测试:数组列表删除节点成功"
    bool removeRes = removeArrayList(a, 1);
    if (removeRes) {
        printf("测试:数组列表删除节点成功\n");
    }
    else {
        printf("测试:数组列表删除节点失败\n");
    }
    for (int i = 0;i < sizeArrayList(a);i++) {
        Node* data = getArrayList(a, i);
        printf("第%d个节点:valueA=%d,valueB=%d\n", i, data->valueA, data->valueB);
    }
    printf("\n");

    // 测试:数组列表销毁，预期为true，打印"测试:数组列表销毁成功"
    destroyRes = destroyArrayList(a);
    if (destroyRes) {
        printf("测试:数组列表销毁成功\n");
    }
    else {
        printf("测试:数组列表销毁失败\n");
    }
}
